package com.lib.krismile.ui.main;

import androidx.annotation.NonNull;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.MutableLiveData;
import androidx.recyclerview.widget.RecyclerView;

import com.lib.krismile.BR;
import com.lib.krismile.R;
import com.lib.krismile.base.adapter.BaseCommonAdapter;
import com.lib.krismile.base.adapter.BaseCommonMultiAdapter;
import com.lib.krismile.base.viewmodel.BaseViewModel;
import com.lib.krismile.entity.MainTestItemEntity;

import java.util.ArrayList;
import java.util.HashMap;


public class MainViewModel extends BaseViewModel {

    /**
     * 测试mvvm databing使用文本
     */
    public MutableLiveData<String> testMvvmText;

    /**
     * 绑定颜色值
     */
    public MutableLiveData<Integer> titleTxtColor;

    //列表适配器
    public BaseCommonMultiAdapter<MainTestItemEntity> adapter;

    public MainViewModel() {
        titleTxtColor = new MutableLiveData<>();
        testMvvmText = new MutableLiveData<>();
    }

    @Override
    protected void initData() {
        //假装获取网络请求
        setTestMvvmText();

        //初始化RecycleView
        HashMap<Integer, Integer> map = new HashMap<>();
        map.put(1, R.layout.layout_test_item);
        map.put(2, R.layout.layout_test_item2);
        adapter = new BaseCommonMultiAdapter<>(map, BR.testEntity);

        ArrayList<MainTestItemEntity> testItemEntities = new ArrayList<>();
        testItemEntities.add(new MainTestItemEntity(1, "测试数据111", "https://ww1.sinaimg.cn/large/0065oQSqly1fu7xueh1gbj30hs0uwtgb.jpg"));
        testItemEntities.add(new MainTestItemEntity(1, "测试数据222", "https://ww1.sinaimg.cn/large/0065oQSqgy1fu39hosiwoj30j60qyq96.jpg"));
        testItemEntities.add(new MainTestItemEntity(2, "测试数据333", "https://ww1.sinaimg.cn/large/0065oQSqly1ftzsj15hgvj30sg15hkbw.jpg"));
        testItemEntities.add(new MainTestItemEntity(1, "测试数据444", "https://ww1.sinaimg.cn/large/0065oQSqly1fu7xueh1gbj30hs0uwtgb.jpg"));
        testItemEntities.add(new MainTestItemEntity(2, "测试数据555", "https://ww1.sinaimg.cn/large/0065oQSqgy1fu39hosiwoj30j60qyq96.jpg"));
        testItemEntities.add(new MainTestItemEntity(1, "测试数据666", "https://ww1.sinaimg.cn/large/0065oQSqly1ftzsj15hgvj30sg15hkbw.jpg"));
        testItemEntities.add(new MainTestItemEntity(1, "测试数据777", "https://ww1.sinaimg.cn/large/0065oQSqly1fu7xueh1gbj30hs0uwtgb.jpg"));
        testItemEntities.add(new MainTestItemEntity(2, "测试数据888", "https://ww1.sinaimg.cn/large/0065oQSqgy1fu39hosiwoj30j60qyq96.jpg"));
        testItemEntities.add(new MainTestItemEntity(1, "测试数据999", "https://ww1.sinaimg.cn/large/0065oQSqly1ftzsj15hgvj30sg15hkbw.jpg"));
        //设置适配器假数据
        adapter.setNewInstance(testItemEntities);
    }


    /**
     * 设置内容你那个
     * 假设网络请求回来获取到的内容
     */
    public void setTestMvvmText() {
        //假设这里做网络请求  成功后的内容
        this.testMvvmText.setValue("我是网络请求回来获取到的内容 ------> 测试文本");

        titleTxtColor.setValue(R.color.color_fbbc04);
    }


}
